/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.skill.executor;

import static com.lineage.server.model.skill.L1SkillId.CONFUSION;
import static com.lineage.server.model.skill.L1SkillId.CONFUSION_ING;

import com.lineage.server.model.L1Character;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.skill.L1SkillExecutor;
import com.lineage.server.packetserver.S_ServerMessage;
import com.lineage.server.packetserver.S_SkillSound;
import com.lineage.server.utils.Random;

/**
 * Class <code>Confusion</code> 幻术师魔法:混乱 (15/10/0).
 * 对敌人造成11点伤害，并有20%~30%机率8秒产生混乱(不能使用魔法)
 * 
 * @author jrwz
 * @version 2012-7-24下午05:42:44
 * @see com.lineage.server.model.skill.executor
 * @since JDK1.7
 */
public final class Confusion extends L1SkillExecutor {

    /**
     * 取得实例.
     * 
     * @return 实例
     */
    public static L1SkillExecutor get() {
        return new Confusion();
    }

    /** 幻术师魔法:混乱 (15/10/0). */
    private Confusion() {
    }

    @Override
    public void execute(final L1Character user, final L1Character cha,
            final L1Character target, final int targetID, final int skillId,
            final int getBuffIconDuration) {
        // 发动判断
        if (user instanceof L1PcInstance) {
            final L1PcInstance pc = (L1PcInstance) user;
            if (!cha.hasSkillEffect(CONFUSION)) {
                final int change = Random.nextInt(100) + 1;
                if (change < (30 + Random.nextInt(11))) { // 30 ~ 40%
                    pc.sendPackets(new S_SkillSound(cha.getId(), 6525));
                    pc.broadcastPacket(new S_SkillSound(cha.getId(), 6525));
                    cha.setSkillEffect(CONFUSION, 2 * 1000); // 发动后再次发动间隔
                                                             // 2秒
                    cha.setSkillEffect(CONFUSION_ING, 8 * 1000);
                    if (cha instanceof L1PcInstance) {
                        final L1PcInstance targetPc = (L1PcInstance) cha;
                        targetPc.sendPackets(new S_ServerMessage(1339)); // 突然感觉到混乱。
                    }
                }
            }
        }
    }

    @Override
    public void stop(final L1Character cha, final int skillId) {
        // TODO Auto-generated method stub
    }
}
